﻿@page "/employeeedit/{DepartmentId}"
@page "/employeeedit/{DepartmentId}/{EmployeeId}"
@using Covid.Shared.Dtos

<h3>Employee Edit</h3>
@if (!Saved)
{
<EditForm Model="@Employee" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInvalidSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary></ValidationSummary>
    <div class="form-group row">
        <label for="no" class="col-sm-2 col-form-label">编号</label>
        <div class="col-sm-10">
            <InputText class="form-control" id="no" @bind-Value="@Employee.No"></InputText>
            <ValidationMessage For="@(() => Employee.No)" />
        </div>
    </div>
    <div class="form-group row">
        <label for="name" class="col-sm-2 col-form-label">姓名</label>
        <div class="col-sm-10">
            <InputText class="form-control" id="name" @bind-Value="@Employee.Name"></InputText>
            <ValidationMessage For="@(() => Employee.Name)" />
        </div>
    </div>
    <div class="form-group row">
        <label for="birthDate" class="col-sm-2 col-form-label">出生日期</label>
        <div class="col-sm-10">
            <InputDate class="form-control" id="birthDate" @bind-Value="@Employee.BirthDate"></InputDate>
        </div>
    </div>
    <div class="form-group row">
        <label for="gender" class="col-sm-2 col-form-label">性别</label>
        <div class="col-sm-10">
            <InputSelect class="form-control" id="gender" @bind-Value="@Employee.Gender">
                @foreach (var value in Enum.GetValues(typeof(Gender)))
                {
                    <option value="@value">@value</option>
                }
            </InputSelect>
        </div>
    </div>
    <div class="form-group row">
        <label for="departmentId" class="col-sm-2 col-form-label">部门</label>
        <div class="col-sm-10">
            <InputSelect class="form-control" id="departmentId" @bind-Value="@EmployeeDepartmentId">
                @foreach (var department in Departments)
                {
                    <option value="@department.Id">@department.Name</option>
                }
            </InputSelect>
        </div>
    </div>

    <div class="form-group row offset-sm-2">
        @if (!string.IsNullOrWhiteSpace(EmployeeId))
        {
            <a class="btn btn-danger" @onclick="@DeleteEmployee">删除</a>
        }

        <button type="submit" class="btn btn-primary">提交</button>
        <button class="btn btn-secondary" @onclick="@GoBack">后退</button>
    </div>
</EditForm>
}
else
{
    <div class="@CssClass" role="alert">
        @Message
    </div>
}